package com.flx.at.spring.code.test.testimportselect.select;

import com.flx.at.spring.code.test.testimportselect.component.ImportSelectA;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @Author: Fenglixiong
 * @Date: 2021/7/3 17:24
 * @Description: ImportBeanDefinitionRegistrar可以动态的注册bean,会加入bean注册表中动态创建bean实例
 */
public class MyBeanRegister implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(ImportSelectA.class);
        registry.registerBeanDefinition("importSelectA",rootBeanDefinition);
    }
}
